<div id="user_contabilitate_jurnal_tva"></div>

<script type="text/javascript">			
Ext.onReady(function(){	

	var fp_user_contabilitate_jurnal_tva;
	var w_user_contabilitate_jurnal_tva;
	var ds_jurnal_tva;
	var cm_jurnal_tva;


    function rdr_total_general(v, params, data) {
            params.attr = 'ext:qtip="Total general"'; // summary column tooltip example
            return v;
    }
    function rdr_total_tva(v, params, data) {
            params.attr = 'ext:qtip="Total TVA"'; // summary column tooltip example
            return v;
    }	
    function rdr_total_valoare(v, params, data) {
            params.attr = 'ext:qtip="Total valoare"'; // summary column tooltip example
            return v;
    }	
    
	fp_user_contabilitate_jurnal_tva = new Ext.FormPanel({
        frame:false,
        title:'<?=$title?>',
        bodyStyle:'padding:5px 5px 0',
		renderTo :'user_contabilitate_jurnal_tva',
        items: [new Ext.form.FieldSet({
            title			:'Criterii:',
            autoHeight		:true,
            defaultType		:'textfield',
			items:[new Ext.form.ComboBox({
						id			:'id-moneda',
						fieldLabel	:'Moneda',
						name		:'n_moneda', 
						allowBlank	:false, 
						blankText		:'Reguli validare <br /><i>Camp obligatoriu</i>',
						editable	:false,								
						lazyRender	:true,
						store		:new Ext.data.Store({
									     id			:'moneda_ds',
										 baseParams	:{saferequest:true,code:'money'},
									     proxy		:new Ext.data.HttpProxy({
									     				url		:'common/getReference/' + Math.random()
									 	}),
						 				reader		: new Ext.data.JsonReader({
												        root	:'DS_MONEY',
												        id		:'value',
												        fields	:['value', 'option']
							         	})
						}),
						hiddenName		:'moneda',
						displayField	:'option',
						valueField		:'value',									
						triggerAction	:'all',
						emptyText		:'[Selectati Moneda]'
					}),new Ext.form.DateField({
						id			:'de-la', 
		            	fieldLabel	:'De la',
		            	name		:'de_la',
		            	allowBlank	:false,
						readOnly 	:true,
						invalidText :'{value} nu este o data valida - Formatul corect este: aaaa-ll-zz',
						blankText	:'Reguli validare <br /><i>Camp obligatoriu</i><br /><i>Format: aaaa-ll-zz</i>',
						format		:'Y-m-d'
				}),new Ext.form.DateField({
						id			:'pana-la', 
		            	fieldLabel	:'Pana la',
		            	name		:'pana_la',
		            	allowBlank	:false,
						readOnly 	:true,
						invalidText :'{value} nu este o data valida - Formatul corect este: aaaa-ll-zz',
						blankText	:'Reguli validare <br /><i>Camp obligatoriu</i><br /><i>Format: aaaa-ll-zz</i>',
						format		:'Y-m-d'
				})	
			]
		})	
        ],

        buttons: [{
			id		:'b-save',	
            text	:'Open',
			formBind:true,
			tooltip	:'Generati raportul',
			iconCls	:'b_save_xml_cls',
			handler	:function(){
				if (!w_user_contabilitate_jurnal_tva) {
							// grid raport jurnal TVA	---------------------------------------------------------
							//-----------------------------------------------------------------------------------	
								
						    ds_jurnal_tva = new Ext.data.Store({
								id			:'table_ds',
						        remoteSort	:true,		
						        proxy: new Ext.data.HttpProxy({
						            url: 'user/contabilitate/jurnaltva/getTable/' + Math.random()		
						        }),
						        reader: new Ext.data.JsonReader({
						            root: 'DS_JURNAL_TVA',
						            totalProperty: 'totalCount',
						            id: 'ID',
						            fields: [
						                {name: 'numar'}, 
										{name: 'client'}, 
										{name: 'data'}, 
										{name: 'valoare', type: 'int'}, 
										{name: 'tva', type: 'int'}, 
										{name: 'total', type: 'int'}
						            ]
						        })
						    });	
					
							ds_jurnal_tva.setDefaultSort('numar', 'desc');
										
						    cm_jurnal_tva = new Ext.grid.ColumnModel([
									{header: "Numar",				dataIndex: 'numar'},
									{header: "Client",				dataIndex: 'client'},
									{header: "Data emiterii",		dataIndex: 'data'},
									{header: "Valoarea",			dataIndex: 'valoare', 	summaryType: 'sum', 	renderer: rdr_total_valoare},
									{header: "Tva",					dataIndex: 'tva', 		summaryType: 'sum', 	renderer: rdr_total_tva},
									{header: "TOTAL",				dataIndex: 'total',		summaryType: 'sum', 	renderer: rdr_total_general}				
							]);
							
					    	cm_jurnal_tva .defaultSortable = true;		
														
						    var summary = new Ext.ux.grid.GridSummary();
													    
							grid_user_contabilitate_jurnal_tva = new Ext.grid.GridPanel({
								id:'gridusercontabilitatejurnaltva-' + Math.random(),
								frame:false,
								anchor:'100%',					
						        store	: ds_jurnal_tva,
						        cm		: cm_jurnal_tva,
						        loadMask: true,
						        viewConfig: {
						            forceFit:true							
						        },
								tbar:[{
							        text: 'Ascunde totalurile',
							        handler: function(btn, e) {
							            summary.toggleSummary();
							        }								
								},'-'],
								plugins: [summary],		
						        bbar: new Ext.PagingToolbar({
									beforePageText:'Pagina&nbsp;',
									afterPageText:'din {0}',
									firstText:'Prima pagina',
									lastText:'Ultima pagina',
									nextText:'Pagina urmatoare',
									prevText:'Pagina precedenta',   
						            pageSize: 15,
						            store: ds_jurnal_tva,
						            displayInfo: true,
						            displayMsg: 'Inregistrari {0} - {1} din {2}',
						            emptyMsg: "No records",
									plugins: new Ext.ux.Andrie.pPageSize({
										  beforeText:'',		
									      afterText: '&nbsp;inreg/pagina',
									      comboCfg: {width: 50}
									      })
								})
							});		
	
							
							// end grid raport jurnal TVA	-----------------------------------------------------
							//-----------------------------------------------------------------------------------	
																
								w_user_contabilitate_jurnal_tva = new Ext.Window({
									id				:'w-user-contabilitate-jurnaltva-' + Math.random(),
									animateTarget	:'b-save',
									width			:900,
									height			:500,
									plain			:true,
									layout			:'fit',
									modal			:true,
									closeAction		:'hide',
									items			:grid_user_contabilitate_jurnal_tva,
									loadMask		:{msg:'Loading...'},
									listeners		:{
										'show'		:function(){
												this.setTitle('Raport | Jurnal TVA [' + Ext.getDom('id-moneda').value + '] de la: ' + Ext.getDom('de-la').value + ' pana la: ' +  Ext.getDom('pana-la').value);
												var values = fp_user_contabilitate_jurnal_tva.form.getValues(false);
												
												ds_jurnal_tva.baseParams = {
													saferequest	: true,
													moneda		: values.moneda,
													dela		: values.de_la,
													panala		: values.pana_la	
												};
												
												ds_jurnal_tva.load({
													params: {
														start: 0,
														limit: 15
													}
												});
										}
									},
						            buttons: [{
									    text		:'Cancel',
										tooltip		:'Renuntati',
									    handler		:function(){
									        w_user_contabilitate_jurnal_tva.hide();
											fp_user_contabilitate_jurnal_tva.getForm().reset();
									    }
									}]
							
								});								
					
				}else {}
				w_user_contabilitate_jurnal_tva.show();	
			}
        },{  
			text: 'Cancel',
			tooltip	:'Renuntati',
			iconCls	:'b_return_cls',	
			handler : function(){
						fp_user_contabilitate_jurnal_tva.getForm().reset();
						goHome();
			}
        },{  
			text: 'Reset',
			tooltip	:'Resetati',	
			handler : function(){
						fp_user_contabilitate_jurnal_tva.getForm().reset();
			}
        }]
    });
	fp_user_contabilitate_jurnal_tva.startMonitoring();	
	
});
</script>
